#include "Rail.h"
#include "RailSketcher.h"

Rail::Rail() {
	this->setType("Rail");
	this->points = new list<Position*>(); 
}

Rail::~Rail() {
	this->points->clear();
	delete(this->points);
}

void Rail::addPoint(Position *position){
	this->points->push_front(position);
}

float Rail::getHeight(){
	return this->height;
}

void Rail::setHeight(float height){
	this->height=height;
}
	
void Rail::removePoint(Position *position){
	this->points->remove(position);
}

void Rail::setPoints( list<Position*> * points )
{
	this->points = points;
}

list<Position*> * Rail::getPoints()
{
	return this->points;
}

Texture * Rail::getTexture(){
	return this->texture;
}

void Rail::setTexture(Texture *texture){
	this->texture = texture;
}

void Rail::setElementColor(Color * color){
	this->elementColor = color;
}

Color * Rail::getElementColor(){
	return this->elementColor;
}

void Rail::setPosition(Position *position){
	this->position = position;
}

Position *Rail::getPosition(){
	return this->position;
}

Color * Rail::getLineColor()
{
	return this->lineColor;
}

void Rail::setLineColor( Color * color )
{
	this->lineColor = color;
}

void Rail::draw()
{
	Sketcher* sketcher = new RailSketcher(this);
	sketcher->draw();
	delete(sketcher);
}

float Rail::getMinXPos(){
	float minPos=100000000;
	for(list<Position*> ::iterator point = this->points->begin();point != this->points->end(); point++){
		if((*point)->getAxisX()<minPos){
			minPos=(*point)->getAxisX();
		}	
	}
	return minPos-this->height;
}
	
float Rail::getMinYPos(){	
	float minPos=100000000;
	for(list<Position*> ::iterator point = this->points->begin();point != this->points->end(); point++){
		if((*point)->getAxisY()<minPos){
			minPos=(*point)->getAxisY();
		}
	
	}
	return minPos-this->height;
}
	
float Rail::getMaxXPos(){	
	float maxPos=-100000000;
	for(list<Position*> ::iterator point = this->points->begin();point != this->points->end(); point++){
		if((*point)->getAxisX()>maxPos){
			maxPos=(*point)->getAxisX();
		}	
	}
	return maxPos+this->height;
}
	
float Rail::getMaxYPos(){
	float minPos=-100000000;
	for(list<Position*> ::iterator point = this->points->begin();point != this->points->end(); point++){
		if((*point)->getAxisY()>minPos){
			minPos=(*point)->getAxisY();
		}
	
	}
	return minPos+this->height;
}

void Rail::addBall(Ball *ball){
	this->balls->push_front(ball);
}

void Rail::removeBall(Ball *ball){
	this->balls->remove(ball);
}